﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using Zzva.Common;
using System.Data;


namespace Zzva.ESB
{
    public class TSysKis
    {

        private static TSysKis mvarSysKis;
        private SqlConnection mvarConnect;


        protected TSysKis(SqlConnection pConnect)
        {
            try { mvarConnect = pConnect; }
            catch (Exception e) { throw e; }
            finally { }
        }



        public static TSysKis GetSystem()
        {
                try
                {
                    if (mvarSysKis == null) { mvarSysKis = GetSysKis(); }

                    return mvarSysKis;
                }

                catch (Exception e) { throw e; }
                finally { }
        }



        private static TSysKis GetSysKis()
        {
            string lConnectStr;
            SqlConnection lConnect;
            TSysKis lSysKis;

            try
            {
                //!!!!!!!!!!!!!
                //достаем Connect из установок
                ////Connect = RegisterLokal.GetSetting("Common", "SysBuhuchConnect");
                
                //lConnectStr = "Data Source=TEH-SRV;Initial Catalog=Kis;Integrated Security=True;";
                //lConnectStr = lConnectStr + "User ID=" + User + ";Password=" + Password + ";";
                lConnectStr = "Data Source=TEH-SRV;Initial Catalog=Kis;Integrated Security=True;"
                            + "User ID=Sergey;Password=Cl254J;";

                lConnect = new SqlConnection(lConnectStr);
                lConnect.Open();
                lSysKis = new TSysKis(lConnect);
                return lSysKis;
            }
            catch (Exception e) { throw e; }
            finally { }
        }


        public DataTable TestGetListMater()
        {
            try
            {

                SqlCommand sql;
                DataTable rst;
                SqlDataAdapter adp;

                sql = new SqlCommand();
                sql.Connection = mvarConnect;

                sql.CommandText = " SELECT DSE, DISP, NAIMDSE"
                                + " FROM DSE"
                                + " WHERE (RAZD = 7)";

                adp = new SqlDataAdapter();
                adp.SelectCommand = sql;
                rst = new DataTable();
                adp.Fill(rst);

                return rst;

            }


            catch (Exception e) { throw e; }
            finally { }
        }



    }
}
